﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using HisoftSmart.Client.AutomationClient;

namespace HisoftSmart.Client.AutomationClient
{
    public class Automation
    {
        public static readonly Automation Instance = new Automation();

        private bool _initialised;

        public void Initialise(string remoteUrl = "")
        {
            if (_initialised)
                return;

            if (Application.Current.RootVisual == null)
                throw new Exception("Automation client initialised too early");

            var configuration = new Configuration()
            {
                RemoteUrl =
                    string.IsNullOrEmpty(remoteUrl) ? Configuration.DefaultRemoteUrl : remoteUrl,
                UiDispatcher = Application.Current.RootVisual.Dispatcher
            };

            var automationClient = new AutomationClient(configuration);
            automationClient.Start();
            Application.Current.Exit += (sender, args) => automationClient.Stop();
            _initialised = true;
        }
    }
}
